Ext.define('Risk.controller.areaInfo.AreaMangeController',{
    extend:'Ext.app.Controller',
    stores:[
        'areaStore.CityStore',
        'areaStore.ProvinceStore',
        'areaStore.TypeStore',
        'areaStore.VillageStore',
        'areaStore.DataStore',
        'areaStore.ChartStore',
        'areaStore.PieStore1',
        'areaStore.PieStore2',
        'areaStore.PieStore3',
        'areaStore.PieStore4'
    ],
    models:[],
    views:[
        'areaInfo.AreaMange',
        'areaInfo.ProjectMange',
        'areaInfo.AreaInfo',
        'areaInfo.Charts',
        'AreaPanel'
    ],
    init:function(){
        this.control({
        	'areaInfo':
        	{
        		render:function(obj)
        		{
        			//区域id
        			var areaId = obj.areaId;
        			//表单
        			var form = obj.down('form').getForm();
        			//获取表单中德数据
        			
        		   if(areaId!=null)
	        			Ext.Ajax.request({
						    url:'area/getInfo.do' ,
						    params:{'id':areaId,_doc:new Date().getMilliseconds()},
						    success:function(response){
						    //成功操作form 注入数据
						    	var result = Ext.JSON.decode(response.responseText).success;
						    	if(result)
						    	{
							    	var o = Ext.JSON.decode(response.responseText).others;
							    	form.setValues(o);
							    	obj.items.get(1).items.get(0).store.load({params:{id:areaId}});
						    	}else
						    	{
						    		obj.getForm().reset();
						    	}
						    },
						    failure:function(response){
						     // 失败操作from 
						    	//obj.getForm().reset();
						    }
						});
        		}
        	},
        	'charts':{
        		render:function(obj)
        		{
        			//项目id
        			var areaId = obj.projid;
        			//表单
        			var form = obj.down('form').getForm();
        			//chart
        			var chart11 = obj.items.get(1).down("chart");
        			//pies
        			var pies1 = obj.items.get(2).down("#pies1");
        			var pies2 = obj.items.get(2).down("#pies2");
        			var pies3 = obj.items.get(2).down("#pies3");
        			var pies4 = obj.items.get(2).down("#pies4");
        			
        		   if(areaId!=null)
	        			Ext.Ajax.request({
						    url:'res/data.do' ,
						    params:{'projid':areaId,_doc:new Date().getMilliseconds()},
						    success:function(response){
						    //成功操作form 注入数据
						    	var result = Ext.JSON.decode(response.responseText).success;
						    	if(result)
						    	{
							    	var o = Ext.JSON.decode(response.responseText).others;
							    	form.setValues(o.form);
							    	//向条形图中加载数据
							    	chart11.store.loadData(o.charts);
							    	//饼图中加载数据
							    	pies1.store.loadData(o.pies1);
							    	pies2.store.loadData(o.pies2);
							    	pies3.store.loadData(o.pies3);
							    	pies4.store.loadData(o.pies4);
							    	//alert(o.pies4.value);
							    	//obj.items.get(1).items.get(0).store.load({params:{id:areaId}});
						    	}else
						    	{
						    		//obj.getForm().reset();
						    	}
						    },
						    failure:function(response){
						     // 失败操作from 
						    	//obj.getForm().reset();
						    }
						});
        		}
        	},
            'projectMange>form button[action = ok]':{
                click:function(){
                    
                }
            },
            'projectMange>form button[action = cancel]':{
                click:function(obj){
                    Ext.MessageBox.show({
	                    title:'警告',
	                    msg:'尚未保存的数据将丢失，确认取消？',
	                    buttons:Ext.Msg.YESNO,
	                    icon:Ext.Msg.WARNING,
	                    fn:function(id){
	                        if(id=='yes'){
	                            obj.up('projectMange').close();
	                        }
	                    }
                   });
                }
            },
            'areaMange>form button[action = cancel]':{
                click:function(obj){
                    Ext.MessageBox.show({ 
                        title:'警告',
                        msg:'尚未保存的数据将丢失，确认取消？',
                        buttons:Ext.Msg.YESNO,
                        icon:Ext.Msg.WARNING,
                        fn:function(id){
                            if(id=='yes'){
                                obj.up('areaMange').close();
                            }
                        }
                   });
                }
            }
            
        })
    }
    
})